<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Vue3 手写 reactive</title>
</head>

<body>
  <div id="app"></div>
  <button id="btn">点我, 又长大了...</button>
  <script src="./xn-vue3.js"></script>
  <script>
    const root = document.querySelector('#app')
    const btn = document.querySelector('#btn')

    const obj = reactive({
      name: '本猿',
      age: '213'
    })
    let double = computed(() => obj.age * 2)
    effect(() => {
      root.innerHTML = `<h1>${obj.name}今年${obj.age}岁了, 乘以2是${double.value}</h1>`
    })
    btn.addEventListener('click', () => {
      obj.age++
    }, false)
  </script>
</body>

</html>